﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StyleMVVM.Validation
{
	public sealed class ValidationRuleResultPart : IValidationRuleResultPart
	{
		public ValidationRuleResultPart(IValidationRuleResult ruleResult,
		                                string partName,
		                                ValidationState state,
		                                string message)
		{
			RuleResult = ruleResult;
			PartName = partName;
			State = state;
			Message = message;
		}

		public IValidationRuleResult RuleResult { get; private set; }

		public string PartName { get; private set; }

		public ValidationState State { get; private set; }

		public string Message { get; private set; }

		public static bool AreEqual(IValidationRuleResultPart leftSide, IValidationRuleResultPart rightSide)
		{
			if (leftSide != null && rightSide != null)
			{
				if (leftSide.PartName != rightSide.PartName)
				{
					return false;
				}

				if (leftSide.Message != rightSide.Message)
				{
					return false;
				}

				if (leftSide.State != rightSide.State)
				{
					return false;
				}

				return true;
			}

			return false;
		}

		public override int GetHashCode()
		{
			return (PartName + Message + State).GetHashCode();
		}
	}
}